{$i-,s-,g+,r-}
{$ifndef modif}{$i modif.inc}{$endif}
Program MaskFiltration;
uses {$ifdef Windows}
     WinCrtx,WinDos,
     {$else}
       {$ifdef fgraph}
       fgraph,
       {$else}
       dos,fgraph,
       {$endif}
     {$ifdef crtx}crtx,{$else}crt,{$endif}
     {$endif}
     pictures;

var vystup,a:string;
    fbr,obr,obp:Picture;
    vbr:VectorPicture;
    i,j:integer;
    MaxP,p:Byte;
    x,y:integer;
    MarkedTime:Longint;
    n:real;
    dispDefined:boolean;


Function GetInterval:Longint; assembler;
asm
	MOV	AH,0
	INT	1Ah
        MOV	AX,DX
        MOV	DX,CX
end;


Label 1,10,20;


Function PercentLineProc(l:integer;var p:picture):Byte; far;
var i:longint;
begin
{$ifdef  Windows}KeyPressed;{$endif}
 if l mod 8 <>0 then exit;
 if l<=0 then exit;
 i:=(longint(100)*l)div p.y;
 write(#13,i:7,'%');
{ if keypressed then halt(1);}
 PercentLineProc:=0;
end;

const Title:array[0..16]of char='Demonstration'#0;
begin
{$ifdef Windows}
ScreenSize.X:=62;
ScreenSize.Y:=10;
WindMax:=ScreenSize;
Move(Title,WindowTitle,Sizeof(Title));
{$endif}

obr.init;
fbr.init;
obp.init;
vbr.init;
{$ifndef  Windows}
  DirectVideo:=False;
  nosound;
{$endif}
writeln(#10#13'<<<Demonstration>>> (c)1995 F&TSoft'+
	#10#13'This programm shows abilities of Toolkit pictures.');
vystup:='';
dispDefined:=false;
n:=1;
a:='A.OKO';
if Paramcount=0 then
	begin
	write('Enter name of input picture:');readln(a);
        end;
for i:=1 to paramcount do
	begin
        if(a[2]='?')or(a[1]='?') then
        	begin
                writeln(#10#13'DEMO picture'#10#13+
			      'Supported file formats are OKO,PCX,RAS,BMP'#10#13);
                halt(1);
                end;
        a:=paramStr(i);
        end;
if a='' then
     begin
     writeln('Error:Unknown filename');
     exit;
     end;

write(#13' Loading');ClrEol;
LoadPicture(obr,a,nil);
if obr.data=nil then
	begin
        writeln(#10#13'Cannot find input picture:''',obr.filename^,'''');
	exit;
        end;
ErasePalette(obr.palette);

InitGraph(-SVGA256,0,'');

TextAttr:=100;

view(obr);
thr(obr,fbr,(1 shl obr.planes) div 2,nil);
crop(fbr,obp,0,0,getMaxX,GetMaxY,nil);	{binar experimental picture}
crop(obr,fbr,0,0,150,150,nil);		{experimental picture}
if obr.filename=nil then
	begin
        writeln('Error:Unknown filename');
        exit;
        end;

for i:=1 to 20 do
	begin
        markedTime:=GetInterval;
	Mask(fbr,Obr,i,nil);
	Obr.View(nil);
        GotoXY(1,1);
        write('Filtrace Maskovanim ',i);
        if keypressed then break;
        end;
write(' stiskni neco pro pokracovani');
readkey;

GotoXY(1,1);
ClrEol;
for i:=1 to 20 do
	begin
        markedTime:=GetInterval;
	Median(fbr,Obr,i,nil);
	Obr.View(nil);
        GotoXY(1,1);
        write('Filtrace Medianem ',i);
        if keypressed then break;
        end;
write(' stiskni neco pro pokracovani');
readkey;

GotoXY(1,1);
ClrEol;
for i:=1 to 20 do
	begin
        markedTime:=GetInterval;
	Gauss(fbr,Obr,i,nil);
	Obr.View(nil);
        GotoXY(1,1);
        write('Filtrace Gausianem ',i);
        if keypressed then break;
        end;
write(' stiskni neco pro pokracovani');
readkey;

GotoXY(1,1);
ClrEol;
for i:=1 to 10 do
	begin
	markedTime:=GetInterval;
	Canny(fbr,Obr,i,2,nil);
	Obr.View(nil);
	GotoXY(1,1);
	write('Detekce hran ',i);
	if keypressed then break;
	end;
write(' stiskni neco pro pokracovani');
readkey;


	{morfologie}
MovePicture(Obp,Obr,nil);
GotoXY(1,1);
ClrEol;
Obr.View(nil);
write('Prahovani -  prah 100');
for i:=1 to 14 do
	begin
	markedTime:=GetInterval;
	Dilatation(Obr,Fbr,El4,nil);
	MovePicture(Fbr,Obr,nil);
	Obr.View(nil);
	GotoXY(1,1);
	write('Dilatace ',i);
	if keypressed then break;
	end;
write(' stiskni neco pro pokracovani');
readkey;


MovePicture(Obp,Obr,nil);
for i:=1 to 14 do
	begin
	markedTime:=GetInterval;
	Erosion(Obr,Fbr,El4,nil);
	MovePicture(Fbr,Obr,nil);
	Obr.View(nil);
	GotoXY(1,1);
	write('Eroze ',i);
	if keypressed then break;
	end;
write(' stiskni neco pro pokracovani');
readkey;


MovePicture(Obp,Obr,nil);
for i:=1 to 20 do
	begin
	markedTime:=GetInterval;
	SeqThin(obr,fbr,L8);
	MovePicture(Fbr,Obr,nil);
	Obr.View(nil);
	GotoXY(1,1);
	write('Ztencovani Elementem L ',i);
	if keypressed then break;
	end;
write(' stiskni neco pro pokracovani');
readkey;


for i:=1 to 20 do
	begin
	markedTime:=GetInterval;
	SeqThin(obr,fbr,E8);
	MovePicture(Fbr,Obr,nil);
	Obr.View(nil);
	GotoXY(1,1);
	write('Oklestovani Elementem E ',i);
	if keypressed then break;
	end;
write(' stiskni neco pro pokracovani');
readkey;



Fbr.Erase;
Dilatation(Obp,Obr,El8,nil);
BinarOperation2(Obp,Obr,XorR,nil);
Obp.View(nil);
GotoXY(1,1);
write('Vektorizace ');
Convert2vector(Obp,Vbr,nil,nil);
delay(100);
ClearDevice;
Vbr.view(nil);



write(' stiskni neco pro ukonceni');
readkey;



CloseGraph;
TextMode(co80);
NormVideo;
if InOutRes<>0 then writeln('IO Error:',Ioresult)
	       else writeln(#13' OK     ');
ClrEol;
obp.Done;
obr.Done;
fbr.Done;
vbr.done;
end.
